<?php
namespace App\Admin\Models;
use Common\BaseModel;
class ViewHomeSelfCenter extends BaseModel
{

    public function initialize()
    {
        parent::initialize();
        $this->setSource('view_home_self_center');
    }
    public function get_list($params){
        $where = '';
        if(isset($params['name']) && !empty($params['name'])){
            $where = "name like '%{$params['name']}%'";
        }
        return $this->find(array(
                $where,
                'order' => 'id desc'
            )
        );
    }

    public function find_by_id_obj($id){
        return $this->findFirstById($id);
    }

    public function find_by_id($id){
        $result = $this->findFirstById($id);
        if($result){
            $result = $result->toarray();
        }else{
            $result =[];
        }
        return $result;
    }

    public function is_count($version,$platform){
        $conditions = "version='{$version}' and platform=$platform";

    }


    //批量修改
    public function batch_update()
    {
        $updateSql = <<<ENT
UPDATE `view_home_self_center`
    SET is_defalut = 1,is_common=0
ENT;
        return $this->getDI()->get('dbMaster')->execute($updateSql);
    }


    //批量修改
    public function batch_update_version($version)
    {
        $updateSql = <<<ENT
UPDATE `view_home_self_center`
SET is_defalut = 1,is_common=1
WHERE version='{$version}'
ENT;
        return $this->getDI()->get('dbMaster')->execute($updateSql);
    }

}
